package operation;

import book.BookList;

import java.util.Scanner;

public class FindOperation implements IOperation {

    @Override
    public void work(BookList bookList) {
        System.out.println("查找图书！");
        System.out.println("请输入你所要查找图书的名字：");

        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int currentSize = bookList.getUsedSize();
        int i = 0;
        for (i = 0; i < currentSize; i++) {
            if (name.equals(bookList.getBook(i).getName())) {
                System.out.println("找到你所查找的书了：");
                System.out.println(bookList.getBook(i));
                return;
            }
        }
        if (i == currentSize) {
            System.out.println("不好意思，没有你所查找的书！");
            return;
        }
    }
}
